﻿

Type clsDrawChart
Private:    
    m_hWnd As hWnd 
    m_prvx As Long = 0
    m_prvy As Long = 0 
    m_x As Long = 0
    m_y As Long = 0
Private:    
    Declare Static Function DrawChartSubclass(ByVal hWin As hWnd, ByVal uMsg As UINT, ByVal wParam As wParam, ByVal lParam As lParam, ByVal uIdSubclass As UINT_PTR, ByVal dwRefData As DWORD_PTR) As LResult
   
'Public:
'    Declare Constructor
'    Declare Destructor
Public:     
    Declare Sub BindWindow(ByVal hWin As hWnd)
    Declare Sub NewPoint()
    Declare Sub SetPoint(ByVal x As Long,ByVal y As Long)    
End Type

Sub clsDrawChart.BindWindow(ByVal hWin As hWnd)
    m_hWnd = hWin
    SetWindowSubclass(hWin, @DrawChartSubclass, Cast(UINT_PTR, hWin), NULL) 
    SetWindowLong(hWin,GWLP_USERDATA,Cast(LONG_PTR,@This))
End Sub

Function clsDrawChart.DrawChartSubclass(ByVal hWin As HWND, ByVal uMsg As UINT, ByVal wParam As WPARAM, ByVal lParam As LPARAM, ByVal uIdSubclass As UINT_PTR, ByVal dwRefData As DWORD_PTR) As LRESULT
    Dim pCtrl As clsDrawChart Ptr = GetWindowLongPtr(hWin,GWLP_USERDATA)
    Select Case uMsg
    Case WM_PAINT
        Dim ps As PAINTSTRUCT
        Dim dc As HDC = BeginPaint(hWin, @ps)
         
        DrawLine(dc,pCtrl->m_prvx,ps.rcPaint.bottom - pCtrl->m_prvy,pCtrl->m_x,ps.rcPaint.bottom - pCtrl->m_y,PS_SOLID,1,0)

        EndPaint(hWin,@ps)         
    'Case WM_SIZE       
        
    Case WM_DESTROY
        RemoveWindowSubclass(hWin,@DrawChartSubclass,uIdSubclass)  
    End Select
    Function = DefSubclassProc(hWin,uMsg,wParam,lParam)
End Function

Sub clsDrawChart.NewPoint()
    m_prvx = 0
    m_prvy = 0
    m_x = 0
    m_y = 0 
End Sub

Sub clsDrawChart.SetPoint(ByVal x As Long, ByVal y As Long)
    m_prvx = m_x
    m_prvy = m_y
    m_x = x
    m_y = y
    InvalidateRect(m_hWnd, NULL, True)
    UpdateWindow(m_hWnd) 
End Sub

























